﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Tycho.Lexer;
using Tycho.Parser.Peg;
using Tycho.Parser.Tokens;

namespace Tycho.Parser.Tests.Peg {
    [TestFixture]
    public class OptionalRuleSpecification {
        [Test]
        public void ShouldParseNothing () {
            var opt = new OptionalRule<object> (new KeywordRule<object> ("x"));

            Token [] tokens = NativeLexer.Lex ("9").ToArray ();

            var result = opt.Parse (tokens, 0, null);
            Assert.IsNotNull (result);
            Assert.AreEqual (0, result.Index);
        }

        [Test]
        public void ShouldParseSomething () {
            var opt = new OptionalRule<object> (new KeywordRule<object> ("x"));

            Token [] tokens = NativeLexer.Lex ("x").ToArray ();

            var result = opt.Parse (tokens, 0, null);
            Assert.IsNotNull (result);
            Assert.AreEqual (1, result.Index);
        }
    }
}